package no.ntnu.fp.model;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.List;

import javax.swing.*;
import javax.swing.border.TitledBorder;

public class guiTest implements ActionListener {

	JButton checkButton, checkButton1, checkButton2, checkButton3;
	JButton checkButton4;
	JButton checkButton5;
	JButton checkButton6;
	
	int ev1 = 1;
	int ev2 = 2;
	int ev3 = -1;
	JFrame frame;
	List<LocalWatchSystem> lws;
	
	private JPanel addPanel(String name, JButton b){
		TitledBorder title;
		JPanel panel = new JPanel(new GridLayout(0, 1));
		title = BorderFactory.createTitledBorder(name);
		panel.setBorder(title);
		JTextArea jtp1 = new JTextArea("Green: "+Math.round((Math.random()*20))); //+" "+"Yellow: "+Math.round((Math.random()*10))+" "+"Red: "+Math.round((Math.random()*4)));
		JTextArea jtp2 = new JTextArea("Yellow: "+Math.round((Math.random()*12)));
		JTextArea jtp3 = new JTextArea("Red: "+Math.round((Math.random()*4)));
		
		b = new JButton("Check");
		b.addActionListener(this);
		panel.add(jtp1);
		panel.add(jtp2);
		panel.add(jtp3);
		panel.add(b);
		return panel;
	}
	
	/**private createMenu(){
		JMenuBar menuBar;
		JMenu menu, submenu;
		JMenuItem menuItem;
		JRadioButtonMenuItem rbMenuItem;
		JCheckBoxMenuItem cbMenuItem;
		
		menuBar = new JMenuBar();
		menu = new JMenu("A Menu");
		menu.setMnemonic(KeyEvent.VK_A);
		menu.getAccessibleContext().setAccessibleDescription(
			"The only menu in this program that has menu items");
		menuBar.add(menu);

		menuItem = new JMenuItem("A text-only menu item",
			KeyEvent.VK_T);
		menuItem.setAccelerator(KeyStroke.getKeyStroke(
			KeyEvent.VK_1, ActionEvent.ALT_MASK));
		menuItem.getAccessibleContext().setAccessibleDescription(
			"This doesn't really do anything");
		menu.add(menuItem);
}
	**/


	
	protected void createGui(){
		frame = new JFrame("GUI-eksempel");
		JPanel panel = new JPanel(new GridLayout(0, 2));
		TitledBorder title;
		title = BorderFactory.createTitledBorder("MASTER WATCH");
		panel.setBorder(title);
		
		 //(lws.get(0)).getGreenCount()+(lws.get(0)).getYellowCount()+(lws.get(0)).getRedCount()
		
		panel.add(addPanel("LWS1", checkButton1));
		panel.add(addPanel("LWS2", checkButton2));
		panel.add(addPanel("LWS3", checkButton3));
		panel.add(addPanel("LWS4", checkButton4));
		panel.add(addPanel("LWS5", checkButton5));
		panel.add(addPanel("LWS6", checkButton6));
		
		frame.setContentPane(panel);
				
		frame.pack();
		frame.setSize(540, 450);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setVisible(true);
	}
	
	public static void main(String[] args) {
		guiTest g = new guiTest();
		LocalWatchSystem l = new LocalWatchSystem();
		//g.addLWS(l);
		new guiTest().createGui();
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		int nr = 0;
		Object d = e.getSource();
		if(d==checkButton1){
			nr = 1;
			//lwc.guiLwc(); elns
		}else if(d==checkButton2){
			nr = 2;
		}else if(d==checkButton3){
			nr = 3;
		}else if(d==checkButton){
			nr = 9;
		}else if(d==checkButton4){
			nr = 4;
		}else if(d==checkButton5){
			nr = 5;
		}else if(d==checkButton6){
			nr = 6;
		}
		System.out.println("Loading Local Watch System "+nr+"..");
		frame.hide();
		new lwsGui().createGui();
	}

	public void addLWS(LocalWatchSystem l){
		lws.add(l);
	}
}
